#! /usr/bin/env python3
#! -*- coding: utf-8 -*-

"""
Utils
author:yooongchun@foxmail.com
"""
from collections import namedtuple

Direction = namedtuple("Direction", ["HORI", "VERT", "DIAG", "RDIAG"])(1, 2, 3, 4)
Chess = namedtuple("Chess", ["WHITE", "BLACK", "EMPTY"])(-1, 1, 0)
Point = namedtuple("Point", ["row", "col"])


class Score(object):
    """各类形态的评分"""
    # score
    WIN = float('inf')
    FAIL = -float('inf')
    FIVE = WIN
    LIVE4 = 1_000_000
    RUSH4 = 2_000
    LIVE3 = 1_000
    DIED3 = 100
    LIVE2 = 10
    DIED2 = 1
    
    # Connected five
    xxxxx = WIN
    # Live four
    oxxxxo = LIVE4
    # Rush four
    oxxxxd = RUSH4
    xoxxx = RUSH4
    xxoxx = RUSH4
    # Live three
    oxxxo = LIVE3
    oxoxxo = LIVE3
    # Died three
    dxxxoo = DIED3
    dxxoxo = DIED3
    dxoxxo = DIED3
    xxoox = DIED3
    xoxox = DIED3
    doxxxod = DIED3
    # Live two
    ooxxoo = LIVE2
    oxoxo = LIVE2
    xoox = LIVE2
    # Died two
    dxooxo = DIED2
    dxxooo = DIED2
    dxoxoo = DIED2
    xooox = DIED2


# 按照分数对case进行排序，便于查找的时候从高到低查找
cases = [(case, getattr(Score, case)) for case in filter(lambda x: x[0] in 'oxd', dir(Score))]
cases = sorted(cases, key=lambda x: x[1], reverse=True)
